//
//  YITableViewHeadView.m
//  一点互助
//
//  Created by rimi on 16/8/19.
//  Copyright © 2016年 shen. All rights reserved.
//

#import "YITableViewHeadView.h"
#import "YIHeadViewScrollview.h"
#import "YIProject.h"
#import "YIMakeAVow.h"
#import "YIPreheat.h"
#import "YIMyWish.h"
#define WIDTH self.bounds.size.width
#define HEIGHT self.bounds.size.height
@interface YITableViewHeadView()
//@property(nonatomic,strong)YIHeadViewScrollview *scrollView;
@property(nonatomic,strong)PackageScrollView *scrollView;
@end
@implementation YITableViewHeadView

-(instancetype)initWithFrame:(CGRect)frame{
       
       self = [super initWithFrame:frame];
       if (self) {
              [self addSubview:self.scrollView];
              [self setViewButton];
       }
       return self;
}
-(void)setViewButton{
       NSArray *imageArr = [NSArray arrayWithObjects:@"首页-许愿",@"首页-查看",@"首页-预热",@"首页-我的", nil];
       NSArray *textArr = [NSArray arrayWithObjects:@"许个愿吧",@"查看愿望",@"预热愿望",@"我的愿望", nil];
       UIView *backView = [[UIView alloc]initWithFrame:CGRectMake(0, 100, WIDTH, 90)];
       backView.backgroundColor = [UIColor whiteColor];
       [self addSubview:backView];
       for (int i = 0; i < 4; i++) {
             
              UIButton *oneBtn = [UIButton buttonWithType:UIButtonTypeCustom];
              oneBtn.frame = CGRectMake((20 + i * 95)* kScreenWidthScale , 10 * kScreenHeightScale, 50, 50);
              oneBtn.backgroundColor = [UIColor clearColor];
              [oneBtn setImage:[UIImage imageNamed:imageArr[i]] forState:0];
              [oneBtn addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
              oneBtn.tag = 100 + i;
              [backView addSubview:oneBtn];
              
              UILabel *lable = [[UILabel alloc]initWithFrame:CGRectMake((20 + i * 95) * kScreenWidthScale, 60 * kScreenHeightScale,  kScreenWidthScale * (WIDTH / 4 - 40) ,kScreenHeightScale* 20)];
              lable.font = [UIFont systemFontOfSize:12];
              lable.textAlignment = NSTextAlignmentCenter;
              lable.text = textArr[i];
              [backView addSubview:lable];

       }
}
-(void)click:(UIButton *)btn{
       //获取视图所在的UIViewController进行跳转
       YIFatherVC *vc = [[YIFatherVC alloc]init];
       if (btn.tag == 100) {
              YIMakeAVow *makeAVow = [[YIMakeAVow alloc]init];
              [[vc superVC:self].navigationController pushViewController:makeAVow animated:YES];
       }
       if (btn.tag == 101) {
              [vc superVC:self].tabBarController.selectedIndex=1;
       }
       if (btn.tag == 102) {
              YIPreheat *preheat = [[YIPreheat alloc]init];
              preheat.title = @"预热愿望";
              [[vc superVC:self].navigationController pushViewController:preheat animated:YES];
       }
       if (btn.tag == 103) {
              YIMyWish *myWish = [[YIMyWish alloc]init];
              myWish.title = @"我的愿望";
              [[vc superVC:self].navigationController pushViewController:myWish animated:YES];
       }
       
       
}
//-(YIHeadViewScrollview *)scrollView{
//       if (!_scrollView) {
//              _scrollView = [[YIHeadViewScrollview alloc]initWithFrame:self.bounds];
//       }
//       return _scrollView;
//}
-(PackageScrollView *)scrollView{
       if (!_scrollView) {
              _scrollView = [[PackageScrollView alloc]initWithFrame:self.bounds];
       }
       return _scrollView;
}
@end
